﻿/// <reference path="models.js" />
(function () {
    var soundTiles = [];

    var loadSoundTiles = function (soundTilePath) {
        return WinJS.xhr({ url: soundTilePath }).then(function (text) {
            var newSoundTiles = JSON.parse(text.responseText);
            for (var i = 0; i < newSoundTiles.length; i++) {
                ViewModels.addSoundTile(newSoundTiles[i].soundSource, newSoundTiles[i].keyBind, newSoundTiles[i].soundType, newSoundTiles[i].soundName);
            }
            ViewModels.loadSoundTiles();
        });
    };

    var getSoundTiles = function () {
        return soundTiles;
    };

    var addSoundTile = function (soundTile) {
        soundTiles.push(soundTile);
    };

    var wipeSoundTiles = function () {
        soundTiles = [];
    };

    WinJS.Namespace.define("Data", {
        loadSoundTiles: loadSoundTiles,
        getSoundTiles: getSoundTiles,
        addSoundTile: addSoundTile,
        wipeSoundTiles: wipeSoundTiles
    });
})();